package com.qf.controller.manager;

import com.github.pagehelper.PageInfo;
import com.qf.entitys.RespBean;
import com.qf.entitys.Rider;
import com.qf.service.RiderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/manager/rider")
public class MRiderController {

    @Resource
    private RiderService service;

    @GetMapping("/list")
    public String list(Rider record, Integer pageindex, HttpServletRequest request){
        PageInfo<Rider> riderPageInfo = service.selectAll(pageindex, record);
        request.setAttribute("pageInfo",riderPageInfo);
        request.setAttribute("riderName",record.getRiderName());
        request.setAttribute("riderPhone",record.getRiderPhone());
        return "manager/RiderList";
    }

    @GetMapping("/nolist")
    public String nolist(Rider record, Integer pageindex, HttpServletRequest request){
        PageInfo<Rider> riderPageInfo = service.selectNo(pageindex, record);
        request.setAttribute("pageInfo",riderPageInfo);
        request.setAttribute("riderName",record.getRiderName());
        request.setAttribute("riderPhone",record.getRiderPhone());
        return "manager/NoRiderList";
    }
    @GetMapping("/backlist")
    public String backlist(Rider record, Integer pageindex, HttpServletRequest request){
        PageInfo<Rider> riderPageInfo = service.selectBack(pageindex, record);
        request.setAttribute("pageInfo",riderPageInfo);
        request.setAttribute("riderName",record.getRiderName());
        request.setAttribute("riderPhone",record.getRiderPhone());
        return "manager/RiderBlackList";
    }

    @GetMapping("/update")
    @ResponseBody
    public RespBean updateRiderstatus(Integer id){
        int i = service.updateRiderstatus(id,2);
        if (i>0){
            return RespBean.success("操作成功!");
        }else {
            return RespBean.error("操作失败!");
        }
    }

    @GetMapping("/onload")
    @ResponseBody
    public RespBean onloadRiderstatus(Integer id){
        int i = service.updateRiderstatus(id,1);
        if (i>0){
            return RespBean.success("操作成功!");
        }else {
            return RespBean.error("操作失败!");
        }
    }

    @GetMapping("/audit")
    @ResponseBody
    public RespBean auditRiderstatus(Integer id){
        int i = service.updateRiderstatus(id,0);
        if (i>0){
            return RespBean.success("操作成功!");
        }else {
            return RespBean.error("操作失败!");
        }
    }

    @GetMapping("/del")
    @ResponseBody
    public RespBean delRiderstatus(Integer id){
        int i = service.delRiderstatus(id);
        if (i>0){
            return RespBean.success("操作成功!");
        }else {
            return RespBean.error("操作失败!");
        }
    }


}
